package com.czkt.springboot_mybatis_test.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.czkt.springboot_mybatis_test.entity.SysRight;
import com.czkt.springboot_mybatis_test.entity.SysRole;
import com.czkt.springboot_mybatis_test.entity.SysRoleRight;
import com.czkt.springboot_mybatis_test.entity.vo.RoleRight;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2024-06-18
 */
@Mapper
public interface SysRoleRightMapper extends BaseMapper<SysRoleRight> {
    @Select("select sr.* from sys_role_right rr ,sys_right sr where  rr.rf_right_code = sr.right_code and rr.rf_role_id = #{roleId};")
    List<SysRight> roleRight(String roleId);

    @Select("update sys_role set role_name = #{roleName},role_desc=#{roleDesc},role_flag=#{roleFlag} where role_id = #{roleId};")
    void updateRoleId(SysRole sysRole);

    @Select("insert into sys_role_right (rf_role_id, rf_right_code) values (#{roleId},#{rightCodes});")
    void insertRfRoleId(@Param("roleId") Long roleId,@Param("rightCodes") String rightCodes);

    @Select("delete from sys_role_right where rf_role_id = #{roleId};")
    void deleteByRfRoleId(Long roleId);

    @Select("select * from sys_role_right where rf_role_id = #{roleId};")
    SysRoleRight selectByRfRoleId(String roleId);

    @Select("delete from sys_role_right where rf_role_id = #{roleId};")
    void delByRfId(String roleId);

    @Select("delete from sys_role where crm.sys_role.role_id = #{roleId};")
    void deleteByRfRoleId(String roleId);
}
